﻿using ModuleGlobalMessage.Util;
using PluginAPI.Core.Attributes;
using PluginAPI.Enums;
using PluginAPI.Events;


namespace ModuleGlobalMessage.Event
{
    /// <summary>
    /// 
    /// </summary>   
    public class GlobalMessageEvent
    {
        [PluginEvent(ServerEventType.PlayerGameConsoleCommandExecuted)]
        public void OnCommandExecuted(PlayerGameConsoleCommandExecutedEvent ev)
        {
            bool isMatch = ev.Command.ToLower() == ("say");
            bool isBC = ev.Command.ToLower() == ("bc");

            if (!isMatch && !isBC) return;

            // 更新
            TeamUtils.GetDescription(ev.Player.Team, ev.Player.Role, out string output);

            string message = string.Join(" ", ev.Arguments);

            MessageBox.Queue($"[{ev.Player.Nickname}][{output}]：{message}");
        }


        [PluginEvent(ServerEventType.WaitingForPlayers)]
        public void OnWaitingForPlayers(WaitingForPlayersEvent ev)
        {
            MessageBox.Enable();
        }

        [PluginEvent(ServerEventType.RoundEnd)]
        public void OnRoundEnd(RoundEndEvent ev)
        {
            MessageBox.Dispose();
        }

        [PluginEvent(ServerEventType.RoundRestart)]
        public void OnRoundRestart(RoundRestartEvent ev)
        {
            MessageBox.Dispose();
        }
    }
}
